
$(function(){
	
	$('#goback').click(function(e){
		e.preventDefault();
		/*window.history.go(-1);*/
		
		window.location.href='/userCenter';
	})

    $('#nav').on('click','a',function(){
        var id = $(this).attr('data-href');
        $(this).addClass('active').siblings('a').removeClass('active');
        $(id).css({display:'block'}).siblings().css({display:'none'});
    })

    $('section').on('click','li',function(){
    	var order_id = $(this).data("orderid");
    	window.sessionStorage['orderid'] = order_id;
    	window.location.href='/userCenter/orderManager/'+order_id;
    })
	
    $.ajax({
    	url:'/userCenter/getOrderList',
    	type:'get',
    	data:{
    		type:0//初审
    	},
    	success:function(data){
    		console.log(data);
    		var html = '';
    		for(var i=0;i<data.length;i++){
    			var name = data[i].name;
    			var order_id = data[i].order_id;
    			var phone = data[i].phone;
	    		var	date = data[i].date;
	    		var	itemType = data[i].itemType;
	    		var	Operator = data[i].Operator;
	    		var	term = data[i].term;
	    		var orderApply = data[i].orderApply;
	    		//判断期数是否为空
	    		if( term == null ){
	    			term = '空'
	    		}
	    		//判断初审进度
	    		if( orderApply == 1){
	    			orderApply = '申请中';
	    		}
	    		if( orderApply == 2){
	    			orderApply = '审核中';
	    		}
	    		if( orderApply == 3){
	    			orderApply = '已拒绝';
	    		}
	    		if( orderApply == 5){
	    			orderApply = '已通过';
	    		}
	    		
	    		html +=`
	    		<li data-orderid="${order_id}">
	                <div class="cs_detail">
	                    <!--上-->
	                    <div class="cs_detail_userInfo">
	                        <!--左-->
	                        <div class="cs_detailInfo cs_detail_userBaseInfo">
	                            <i class="inlineBlockImg cs_detail_userBaseInfo_logo"></i>
	                            <span class="cs_detail_userBaseInfo_name">${name}</span>
	                            <span class="cs_detail_userBaseInfo_phone">${phone}</span>
	                        </div>
	                        <!--右-->
	                        <div class="cs_detailInfo cs_detail_userDateInfo">
	                            <i class="inlineBlockImg cs_detail_userDateInfo_logo"></i>
	                            <span class="cs_detail_userDateInfo_Date">${date}</span>
	                        </div>
	                    </div>
	                    <!--下-->
	                    <div class=" cs_detail_userInfo cs_detail_orderInfo">
	                        <!--左-->
	                        <div class="cs_detailInfo cs_detail_orderCarInfo">
	                            <i class="inlineBlockImg cs_detail_orderCarInfo_logo"></i>
	                            <span  class="cs_detail_orderCarInfo_text">${itemType}</span>
	                            <span  class="cs_detail_orderCarInfo_text">${term}</span>
	                            <span  class="cs_detail_orderCarInfo_text">${Operator}</span>
	                        </div>
	                        <!--右-->
	                        <div class="cs_detail_orderProgressInfo">
	                            <p class="progress">${orderApply}</p>
	                            <p class="seeDetail">查看详情</p>
	                        </div>
	                    </div>
	                </div>
	           </li>
	    		`
    		}
    		$('#cs ul').html(html);
    	}
    })
    
    //复审
        $.ajax({
    	url:'/userCenter/getOrderList',
    	type:'get',
    	data:{
    		type:1//复审
    	},
    	success:function(data){
    		var html = '';
    		for(var i=0;i<data.length;i++){
    			var name = data[i].name;
    			var order_id = data[i].order_id;
    			var phone = data[i].phone;
	    		var	date = data[i].date;
	    		var	itemType = data[i].itemType;
	    		var	Operator = data[i].Operator;//运营商
	    		var	term = data[i].term;
	    		var carConfigure = data[i].carConfigure;//车型配置
	    		var progressRate = data[i].progressRate;//审核进度百分比
	    		var progressRateImg = '';
	    		console.log(progressRate);
	    		//判断期数是否为空
	    		if( term == null ){
	    			term = '空'
	    		}
	    		//判断车型配置是否为空
	    		if( carConfigure == null ){
	    			carConfigure = '空'
	    		}
	    		//判断审核进度百分比
	    		if( progressRate == 1){
	    			progressRateImg = '/assets/img/进度条-拷贝@2x.png';
	    		}
	    		if( progressRate == 2){
	    			progressRateImg = '/assets/img/进度条-拷贝-2@2x.png';
	    		}
	    		if( progressRate == 3){
	    			progressRateImg = '/assets/img/进度条@2x.png';
	    		}
	    		
	    		html +=`
	    		<li data-orderid="${order_id}">
	                <div class="cs_detail">
	                    <!--上-->
	                    <div class="cs_detail_userInfo">
	                        <!--左-->
	                        <div class="cs_detailInfo cs_detail_userBaseInfo">
	                            <i class="inlineBlockImg cs_detail_userBaseInfo_logo fs_detail_userBaseInfo_logo"></i>
	                            <span class="cs_detail_userBaseInfo_name">${name}</span>
	                            <span class="cs_detail_userBaseInfo_phone">${phone}</span>
	                        </div>
	                        <!--右-->
	                        <div class="cs_detailInfo cs_detail_userDateInfo">
	                            <i class="inlineBlockImg cs_detail_userDateInfo_logo"></i>
	                            <span class="cs_detail_userDateInfo_Date">${date}</span>
	                        </div>
	                    </div>
	                    <!--下-->
	                    <div class=" cs_detail_userInfo cs_detail_orderInfo">
	                        <!--左-->
	                        <div class="cs_detailInfo cs_detail_orderCarInfo ">
	                            <div class='cs_detail_orderCarInfo_border'>
	                                <div class="fs_detail_orderCarInfo_car">
	                                    <i class="inlineBlockImg fs_detail_orderCarInfo_logo"></i>
	                                    <span class="fs_detail_orderCarInfo_text">${carConfigure}</span>
	                                </div>
	                                <div>
	                                    <span  class="cs_detail_orderCarInfo_text">${itemType}</span>
	                                    <span  class="cs_detail_orderCarInfo_text">${term}</span>
	                                    <span  class="cs_detail_orderCarInfo_text">${Operator}</span>
	                                </div>
	                            </div>
	                        </div>
	                        <!--右-->
	                        <div class="cs_detail_orderProgressInfo">
	                            <div>
	                                <img class="inlineBlockImg fs_detail_orderProgressInfo_logo" src='${progressRateImg}'/>
	                            </div>
	                            <p class="fs_detail_orderProgressInfo_text">审核中</p>
	                        </div>
	                    </div>
	                </div>
	           </li>
	    		`
    		}
    		$('#fs ul').html(html);
    	}
    })
    
        //放款
        $.ajax({
    	url:'/userCenter/getOrderList',
    	type:'get',
    	data:{
    		type:2//放款
    	},
    	success:function(data){
    		var html = '';
    		for(var i=0;i<data.length;i++){
    			var name = data[i].name;
    			var order_id = data[i].order_id;
    			var phone = data[i].phone;
	    		var	date = data[i].date;
	    		var	itemType = data[i].itemType;
	    		var	Operator = data[i].Operator;//运营商
	    		var	term = data[i].term;
	    		var carConfigure = data[i].carConfigure;//车型配置
	    		var loanAmount = data[i].loanAmount;//放款金额
	    		//判断期数是否为空
	    		if( term == null ){
	    			term = '空'
	    		}
	    		var loanAmountArr = String(loanAmount).split('').reverse();
	
	    		for(var r = 0; r < loanAmountArr.length; r++){  
	    			 if(r % 4 == 3){  
	    			     loanAmountArr.splice(r, 0, ',');  
	    			 }  
	    		}  
	    		 loanAmount = loanAmountArr.reverse().join('');
	    				    		
	    		html +=`
	    		<li data-orderid="${order_id}">
	                <div class="cs_detail">
	                    <!--上-->
	                    <div class="cs_detail_userInfo">
	                        <!--左-->
	                        <div class="cs_detailInfo cs_detail_userBaseInfo">
	                            <i class="inlineBlockImg cs_detail_userBaseInfo_logo fs_detail_userBaseInfo_logo"></i>
	                            <div class='cs_detail_userBaseInfo_border'>
		                            <span class="cs_detail_userBaseInfo_name">${name}</span>
			                        <div class='cs_detail_userBaseInfo_phone_border'>
			                        	<span class="cs_detail_userBaseInfo_phone">${phone}</span>
			                        </div>
	                            </div>
	                            
	                        </div>
	                        <!--右-->
	                        <div class="cs_detailInfo cs_detail_userDateInfo">
	                            <span class="fk_detail_userDateInfo_text">放款时间：</span>
	                            <span class="fk_detail_userDateInfo_textDate">${date}</span>
	                        </div>
	                    </div>
	                    <!--下-->
	                    <div class=" cs_detail_userInfo cs_detail_orderInfo">
	                        <!--左-->
	                        <div class="cs_detailInfo cs_detail_orderCarInfo ">
	                            <div class='cs_detail_orderCarInfo_border'>
	                                <div class="fs_detail_orderCarInfo_car">
	                                    <i class="inlineBlockImg fs_detail_orderCarInfo_logo"></i>
	                                    <div class='fs_detail_orderCarInfo_text_border'><span class="fs_detail_orderCarInfo_text">${carConfigure}</span></div>
	                                </div>
	                                <div class='fs_detail_orderCarInfo_carType'>
	                                    <span  class="cs_detail_orderCarInfo_text">${itemType}</span>
	                                    <span  class="cs_detail_orderCarInfo_text">${term}</span>
	                                    <span  class="cs_detail_orderCarInfo_text">${Operator}</span>
	                                </div>
	                            </div>
	                        </div>
	                        <!--右-->
	                        <div class="fk_detail_orderProgressInfo ">
	                            <p class="fk_detail_orderProgressInfo_text">已放款</p>
	                            <p class="fk_detail_orderProgressInfo_money">${loanAmount}<span class="fk_detail_orderProgressInfo_money_text">元</span></p>
	                        </div>
	                    </div>
	                </div>
	            </li>
	    		`
    		}
    		$('#fk ul').html(html);
    	}
    })
    
    
})





